<?php
define('IN_ADMIN', TRUE);
require dirname(__FILE__).'/includes/global_admin.func.php';
require dirname(__FILE__).'/includes/common.inc.php';
require MOD_ROOT.'log/log.class.php';
require 'form.class.php';
require_once MOD_ROOT.'cache/cache.func.php';
require_once 'version.inc.php';

//require WWW_ROOT.'includes/languages/'.LANG.'/admin.lang.php';

if(!isset($module)){
	header("Location:?module=frames");
}

$file = $file ? $file : $module;
preg_match("/^[0-9A-Za-z_-]+$/", $module) or showmessage('Invalid Request.');


$action = isset($action) ? $action : '';
$catid = isset($catid) ? intval($catid) : 0;
$specialid = isset($specialid) ? intval($specialid) : 0;
if(!isset($forward) && str_exists(HTTP_REFERER, '?')) $forward = HTTP_REFERER;

session_start();

if($_userid && $_groupid == 1 && $_SESSION['is_admin'] == 1)
{
	$ROLE = cache_read('role.php');
	$GROUP = cache_read('member_group.php');
	$POS = cache_read('position.php');
	$STATUS = cache_read('status.php');
	
	
	//$_roleid = cache_read('admin_role_'.$_userid.'.php');
	
	include_once(MOD_ROOT.'admin/admin.class.php');
	$a = new admin($_userid);
	$_roleid = $a->get_admin_role();
	
	
	if(!$_roleid) showmessage('您没有任何角色权限！');
	require MOD_ROOT.'priv/priv_role.class.php';
	$priv_role = new priv_role();
	
	if(!$priv_role->module()) showmessage('您没有操作权限！');
}

// 该条件防止页面无限循环的跳转到登录页
elseif($module != 'member' && $action != 'login')
{
	showmessage('请登录！', '?module=member&action=login&forward='.urlencode(URL),1,1);
}

$log = new log();
if(/*ADMIN_LOG &&*/ $module != 'database' && !in_array($action, array('get_menu_list', 'menu_pos')))
{
	$log->set('admin', 0);
	$log->add();
}

/*if(!@include WWW_ROOT.$M['path'].'admin/admin.inc.php') showmessage('The file ./'.$M['path'].'admin.inc.php is not exists!');
if(!@include WWW_ROOT.(isset($M['path']) ? $M['path'] : '').'admin/'.$file.'.inc.php') showmessage("The file ./{$M['path']}admin/{$file}.inc.php is not exists!");*/
	

/*解决iis下上传文件，<input name="" type="file" />表单提交的时候，会产生一个$file（$file的变量名与定义的name有关，表单的其他元素不会产生该问题）的变量的问题（apache不会产生该问题） */ 
if(strpos($file, '.tmp') !== false){ // by aming
	$file = $module; 
}

// 系统模块目录
$file_path = WWW_ROOT."modules/$module/".$file."_admin.inc.php";
if(file_exists($file_path)){
	include($file_path);
}
else{
	// 自定义模块目录
	$site_module_file_path = WWW_ROOT."sites/modules/$module/".$file."_admin.inc.php";
	if(file_exists($site_module_file_path)){
		include($site_module_file_path);
	}
	else{
		showmessage("{$site_module_file_path}文件不存在");
	}
}

?>